<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java 异常机制深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 1rem;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 80%;
            background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-inline {
            background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
            padding: 0.2rem 0.5rem;
            border-radius: 0.25rem;
            font-family: 'Courier New', monospace;
            font-size: 0.9em;
            color: #5a67d8;
            border: 1px solid #e2e8f0;
        }
        
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f6f9fc 0%, #e9ecef 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            margin: 1.5rem 0;
            border-radius: 0.5rem;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fade-in {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fade-in">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                Java 异常机制
                <span class="block text-3xl md:text-4xl mt-4 font-light opacity-90">深度解析与最佳实践</span>
            </h1>
            <p class="text-xl md:text-2xl font-light max-w-3xl mx-auto leading-relaxed">
                掌握检查型异常与运行时异常的本质区别，构建更加健壮的 Java 应用程序
            </p>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8 animate-fade-in">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>Java 的世界里，异常处理机制是保证程序健壮性的重要基石。Java 将异常精心设计为两大类别：<strong class="text-purple-700">检查型异常（Checked Exceptions）</strong> 和 <strong class="text-purple-700">运行时异常（Unchecked Exceptions）</strong>。理解这两类异常的本质区别，是每个 Java 开发者必须掌握的核心技能。
            </p>
        </div>

        <!-- Exception Hierarchy Visualization -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8 animate-fade-in">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 text-center">
                <i class="fas fa-sitemap mr-3 feature-icon"></i>异常体系结构
            </h2>
            <div class="mermaid">
                graph TD
                    A[Throwable] --> B[Error]
                    A --> C[Exception]
                    C --> D[RuntimeException<br/>运行时异常]
                    C --> E[其他 Exception<br/>检查型异常]
                    D --> F[NullPointerException]
                    D --> G[ArrayIndexOutOfBoundsException]
                    D --> H[IllegalArgumentException]
                    E --> I[IOException]
                    E --> J[SQLException]
                    E --> K[ClassNotFoundException]
                    
                    style A fill:#f9f,stroke:#333,stroke-width:4px
                    style C fill:#bbf,stroke:#333,stroke-width:2px
                    style D fill:#fbb,stroke:#333,stroke-width:2px
                    style E fill:#bfb,stroke:#333,stroke-width:2px
            </div>
        </div>

        <!-- Checked Exceptions Section -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8 animate-fade-in">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-shield-alt mr-3 feature-icon"></i>检查型异常（Checked Exceptions）
            </h2>
            
            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                检查型异常是 Java 异常机制中的"守门员"，它们在编译时期就要求开发者必须处理，体现了 Java 对程序健壮性的严格要求。这类异常通常源于外部环境的不确定性，如文件系统、网络连接或数据库操作。
            </p>

            <div class="grid md:grid-cols-2 gap-6 mb-6">
                <div class="highlight-box">
                    <h3 class="text-xl font-bold mb-3 text-purple-700">
                        <i class="fas fa-check-circle mr-2"></i>核心特征
                    </h3>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-angle-right mr-2 text-purple-500"></i><strong>编译时强制检查</strong>：必须显式处理</li>
                        <li><i class="fas fa-angle-right mr-2 text-purple-500"></i><strong>可恢复性</strong>：通常表示可以恢复的错误</li>
                        <li><i class="fas fa-angle-right mr-2 text-purple-500"></i><strong>外部依赖</strong>：多与外部资源交互相关</li>
                    </ul>
                </div>
                
                <div class="highlight-box">
                    <h3 class="text-xl font-bold mb-3 text-purple-700">
                        <i class="fas fa-code mr-2"></i>常见示例
                    </h3>
                    <ul class="space-y-2 text-gray-700">
                        <li><code class="code-inline">IOException</code> - I/O 操作异常</li>
                        <li><code class="code-inline">SQLException</code> - 数据库操作异常</li>
                        <li><code class="code-inline">FileNotFoundException</code> - 文件未找到</li>
                        <li><code class="code-inline">ClassNotFoundException</code> - 类加载失败</li>
                    </ul>
                </div>
            </div>

            <div class="bg-purple-50 rounded-lg p-6">
                <h4 class="text-lg font-bold mb-3 text-purple-800">
                    <i class="fas fa-lightbulb mr-2"></i>应用场景与最佳实践
                </h4>
                <p class="text-gray-700 leading-relaxed">
                    检查型异常适用于那些调用者能够合理恢复的异常情况。例如，当读取配置文件失败时，程序可以使用默认配置继续运行；当网络连接失败时，可以实施重试策略。使用检查型异常能够强制调用者考虑异常情况，提高代码的健壮性。
                </p>
            </div>
        </div>

        <!-- Runtime Exceptions Section -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8 animate-fade-in">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-exclamation-triangle mr-3 feature-icon"></i>运行时异常（Unchecked Exceptions）
            </h2>
            
            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                运行时异常是程序逻辑错误的"警报器"。它们不需要强制处理，因为这类异常通常表示编程错误，应该通过改进代码质量来避免，而不是通过异常处理来掩盖。
            </p>

            <div class="grid md:grid-cols-2 gap-6 mb-6">
                <div class="highlight-box">
                    <h3 class="text-xl font-bold mb-3 text-purple-700">
                        <i class="fas fa-times-circle mr-2"></i>核心特征
                    </h3>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-angle-right mr-2 text-purple-500"></i><strong>运行时发生</strong>：编译器不强制处理</li>
                        <li><i class="fas fa-angle-right mr-2 text-purple-500"></i><strong>编程错误</strong>：通常由代码缺陷引起</li>
                        <li><i class="fas fa-angle-right mr-2 text-purple-500"></i><strong>预防为主</strong>：应通过代码改进避免</li>
                    </ul>
                </div>
                
                <div class="highlight-box">
                    <h3 class="text-xl font-bold mb-3 text-purple-700">
                        <i class="fas fa-bug mr-2"></i>常见示例
                    </h3>
                    <ul class="space-y-2 text-gray-700">
                        <li><code class="code-inline">NullPointerException</code> - 空指针异常</li>
                        <li><code class="code-inline">ArrayIndexOutOfBoundsException</code> - 数组越界</li>
                        <li><code class="code-inline">IllegalArgumentException</code> - 非法参数</li>
                        <li><code class="code-inline">ArithmeticException</code> - 算术异常</li>
                    </ul>
                </div>
            </div>

            <div class="bg-purple-50 rounded-lg p-6">
                <h4 class="text-lg font-bold mb-3 text-purple-800">
                    <i class="fas fa-shield-virus mr-2"></i>预防策略
                </h4>
                <p class="text-gray-700 leading-relaxed">
                    运行时异常的最佳处理方式是预防。通过参数校验、空值检查、边界条件判断等防御性编程技术，可以有效避免大部分运行时异常。记住：运行时异常通常意味着代码存在缺陷，应该修复代码而不是捕获异常。
                </p>
            </div>
        </div>

        <!-- Comparison Section -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8 animate-fade-in">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 text-center">
                <i class="fas fa-balance-scale mr-3 feature-icon"></i>核心差异对比
            </h2>
            
            <div class="overflow-x-auto">
                <table class="w-full text-left">
                    <thead>
                        <tr class="border-b-2 border-purple-200">
                            <th class="py-4 px-6 text-purple-700 font-bold">对比维度</th>
                            <th class="py-4 px-6 text-purple-700 font-bold">检查型异常</th>
                            <th class="py-4 px-6 text-purple-700 font-bold">运行时异常</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="border-b border-gray-200 hover:bg-purple-50 transition-colors">
                            <td class="py-4 px-6 font-semibold">检查时机</td>